﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace GameServer.Networking.Packets
{
    class PACKET_PLAYER_NUMBER : Packet
    {
        public PACKET_PLAYER_NUMBER(Virtual_Objects.Room.virtualRoom Room)
        {
            try
            {
                newPacket(29968);
                addBlock(1);
                try
                {
                    addBlock(Room.Flags);
                    for (int I = 0; I < 32; I++)
                        addBlock(Room.Flags[I]);
                }
                catch
                {
                    addBlock(0);
                    addBlock(0);
                }

                addBlock(766);

                addBlock(Room.Players.Count);
                foreach (Virtual_Objects.User.virtualUser User in Room.Players)
                {
                    addBlock(Room.getIDOfPlayer(User));
                    addBlock(-1);
                    addBlock(0);
                    addBlock(0);
                    addBlock(User.Class);
                    addBlock(User.Weapon);
                    addBlock(User.Health);
                    addBlock(-1);
                    addBlock(-1);
                }
                try
                {
                    ArrayList changedVehicles = new ArrayList();
                    foreach (Vehicle Object in Room.Vehicles)
                    {
                        if (Object.ChangedCode != string.Empty && Object.Health > 0)
                        {
                            changedVehicles.Add(Object);
                        }
                    }
                    addBlock(changedVehicles.Count.ToString());
                    foreach (Vehicle Object in changedVehicles)
                    {
                        addBlock(Room.VehicleIndexOf(Object));
                        addBlock(Object.Health);
                        addBlock(Object.PositionX + ".0000");
                        addBlock(Object.PositionY + ".0000");
                        addBlock(Object.PositionZ + ".0000");
                        addBlock(Object.AxisX + ".0000");
                        addBlock(Object.AxisY + ".0000");
                        addBlock(Object.AxisZ + ".0000");
                        addBlock(Object.AxisZ + ".0000");
                        addBlock(Object.ChangedCode);
                        addBlock(0);
                        addBlock(0);
                        addBlock(-75);
                        addBlock(0);
                        addBlock(0);
                        addBlock(0);
                        addBlock(53);
                        addBlock(0);
                    }
                }
                catch
                {
                    addBlock(0);
                }
            }
            catch
            {
                //Log.WriteError("Error on PACKET_PLAYER_NUMBER");
            }
        }
    }
}